package com.haoze.nurseapp.service.impl;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.sql.*;

public class MyQuartzJob implements Job {

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        /**
         * 扫描二维码之后需要拿到二维码内的三方barcode去三方sqlserver中查询视图，来确定当前静配药房记录是否已加药
         */
        String user = "sa";
        String password = "Jack110110";
        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
        String url = "jdbc:sqlserver://172.20.6.126:1433;DatabaseName=ZHY_PIVAS_CZEY;";
        String sql = "SELECT a.barcode,a.batch,a.* " +
                "FROM dbo.pat_drug_master a ";
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
            // 连接数据库
            conn = DriverManager.getConnection(url, user, password);
            // 建立Statement对象
            stmt = conn.createStatement();
            // 执行数据库查询语句
            rs = stmt.executeQuery(sql);
            //while (rs.next()) {
                /*String patientId = rs.getString("patient_id");
                String deptName = rs.getString("dept_name");
                System.out.println("住院号: "+patientId+"; "+"科室: "+deptName);*/
                System.out.println(rs);
            //}
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try{
                if (rs != null) {
                    rs.close();
                    rs = null;
                }
                if (stmt != null) {
                    stmt.close();
                    stmt = null;
                }
                if (conn != null) {
                    conn.close();
                    conn = null;
                }
            } catch (SQLException e){
                e.printStackTrace();
            }
        }
    }
}
